package com.zhanglijie.improve.atomic.five;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/9/10 0010 15:22
 * 单线程测试
 */
public class TestAtomicArray {
    public static void main(String[] args) {
        AtomicIntegerArray array = new AtomicIntegerArray(10);
        for (int i = 0; i < array.length(); i++) {
            System.out.println("index _"+i+" value= "+array.get(i));
        }
        array.set(2,10);
        System.out.println("index _"+2+" value = "+array.get(2));
        array.addAndGet(2,10);
        System.out.println("index _"+2+" value = "+array.get(2));

        if(array.compareAndSet(2,20,40)) {
            System.out.println("index _" + 2 + " value = " + array.get(2));
        }


    }
}
